<?php

/**
 * dossier form.
 *
 * @package    e-DSL
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrinePluginFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class dossierForm extends PlugindossierForm
{
  public function configure()
  {
  	$this->validatorSchema->setOption('allow_extra_fields', true);
  	$this->widgetSchema['delaisMini'] = new sfWidgetFormInputHidden();
  	
  	$q=Doctrine_Query::create()
	    	->select('a.id as id, a.description  as name')
		    ->from('typedossier a') 
		    ->orderBy('a.description');
 	$q->andWhere('a.pere_id is null');
 	
	$this->widgetSchema['typePere'] = new sfWidgetFormDoctrineChoice(
		 								array( 'model' => 'typedossier',
		 								'query' => $q,
		 								'add_empty' => sfContext::getInstance()->getI18N()->__('Please select a value...')));  	
	$this->offsetGet('typePere')->getWidget()->setAttributes(array(
			'tmt:invalidindex'=> "0",
			'tmt:errorclass'=> "error",
			'tmt:message'=> "Champ obligatoire",
			'onchange'=>'refreshCandidatesType()',
			'class'=> "combobox required form",
	));
	
    $this->getWidget('typePere')->setLabel('Type dossier *');
  }

  public function setWidgetsLocal($region,$departement){

  	if ($region=='') $region=0;
	if ($departement=='') $departement=0 ;
  	$arrayvide = array();

	$$regionObj = new region;
	$departaments = $$regionObj->getArrayDepartements($UM);
	unset($$regionObj);
	if(count($departaments)==2){ 
  		foreach($departaments as $def =>$name){
			if($def!=0)
				$departement = $def;
		}
	}
	if(!array_key_exists($departement,$departaments)) $departement = 0; /*Il faut changer le default car il ne fait pas partie des candidates*/
	$att = $this->offsetGet('departementClient_id')->getWidget()->getAttributes();
	$this->setMyWidget('departementClient','',$departaments, $departement);
	unset($departaments);
	unset($departement);
	$this->offsetGet('departementClient_id')->getWidget()->setAttributes($att);
	
  }
  
}
